/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package imat;

import java.awt.Dimension;
import java.util.List;
import javax.swing.JPanel;
import se.chalmers.ait.dat215.project.Order;

/**
 *
 * @author Gustav
 */
public class HistoryPresenter {
    private HistoryView historyView;

    public HistoryPresenter (HistoryView view) {
        historyView = view;
    }

    public void fillPanel() {
        JPanel panel = historyView.getHistoryPanel();

        panel.removeAll();

        List<Order> orders = DataHandler.getInstance().getOrders();
        for (Order order : orders) {
            HistoryItemView view = new HistoryItemView();
            view.setOrder(order);
            panel.add(view);
        }

        // Scrollbar fix
        JPanel scrollPanel = historyView.getScrollPanel();
        scrollPanel.setPreferredSize(new Dimension(0, 50+orders.size()*50));
        scrollPanel.revalidate();

        panel.repaint();
        panel.revalidate();
    }
}
